using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;

namespace TestProject
{
	/// <summary>
	/// Represents an entry in the firsttime table in the database. These are the users that haven't log in yet. 
	/// </summary>
	public class Firsttime
	{
		private int m_user_ID;
		
		public Firsttime ()
		{
		}
		
		public int user_ID
		{
			set
			{
				m_user_ID = value;
			}
			
			get
			{
				return m_user_ID;
			}
		}
		
		/// <summary>
		/// Adds a first time entry in the database. 
		/// </summary>
		/// <param name="user_ID">
		/// A <see cref="System.Int32"/> The user_ID to be added into the firsttime table.
		/// </param>
		public static void addFirstTime(int user_ID)
		{
			MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString);
	        try
			{
				conn.Open();
				string newStatement = "INSERT INTO firsttime (user_ID) "
					+ "VALUES ('"+user_ID+"')";
		        MySqlCommand newCmd = new MySqlCommand(newStatement, conn);
				newCmd.ExecuteNonQuery();
			}
			catch(Exception e)
			{
				Console.WriteLine(e.ToString());
			}
		    conn.Close();
		}
		
		/// <summary>
		/// Deletes a first time entry in the database. 
		/// </summary>
		/// <param name="user_ID">
		/// A <see cref="System.Int32"/> The corresponding user_ID of the entry to be deleted.
		/// </param>
		public static void deleteFirstTime(int user_ID)
		{
			MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySQL"].ConnectionString);
	        try
			{
				conn.Open();				
				string statement = "DELETE FROM firsttime where user_ID='"+user_ID+"'";
		        MySqlCommand cmd = new MySqlCommand(statement, conn);
				cmd.ExecuteNonQuery();
			}
			catch(Exception e)
			{
				Console.WriteLine(e.ToString());
			}
		    conn.Close();	
		}
	}
}

